package com.smartstate.autoMaticControl.controller;


import com.alibaba.cloud.commons.lang.StringUtils;
import com.smartstate.autoMaticControl.entity.Dedusting;
import com.smartstate.autoMaticControl.entity.Equipment;
import com.smartstate.autoMaticControl.entity.TreeNode;
import com.smartstate.autoMaticControl.service.EquipmentBoardService;
import com.smartstate.autoMaticControl.util.TreeBuild;
import com.smartstate.autoMaticControl.service.DeviceDisService;
import com.smartstate.autoMaticControl.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 *  自控  设备分布和设备列表  控制器暂存数据中台
 */
@RestController
@Slf4j
@Api(tags = {"设备分布控制器"})
@RequestMapping("/deviceDistribute")
public class DeviceDisController {


    @Resource
    private DeviceDisService deviceDisService;

    @Resource
    private EquipmentBoardService equipmentBoardService;


    @PostMapping("/getList")
    @ApiOperation(value = "获取所有的设备列表")
    public ResultVO<List<Equipment>> getList(@RequestBody Equipment  equipment) {
        return  ResultVO.ok(deviceDisService.getList(equipment));
    }

    @PostMapping("/getDeviceById")
    @ApiOperation(value = "根据设备ID获取设备信息")
    public ResultVO<Equipment> getDeviceById(@RequestBody Equipment  equipment) {
        if(StringUtils.isNotBlank(equipment.getDeviceId())){
            return  ResultVO.ok(deviceDisService.getDeviceById(equipment.getDeviceId()));
        }
        return  ResultVO.fail("参数缺失， 请输入参数");
    }

    @PostMapping("/ConditioningSystemAll")
    @ApiOperation(value = "获取空调系统信息")
    public ResultVO<List<Equipment>> ConditioningSystemAll(@RequestBody Equipment  equipment) {
            return  ResultVO.ok(deviceDisService.ConditioningSystemAll(equipment));
    }

    @PostMapping("/PureWaterAll")
    @ApiOperation(value = "获取纯水系统信息")
    public ResultVO<List<Equipment>> PureWaterAll(@RequestBody Equipment  equipment) {
            return  ResultVO.ok(deviceDisService.PureWaterAll(equipment));
    }


    @GetMapping("/treeTest")
    @ApiOperation(value = "自控首页点位设备详情数据")
    public ResultVO treeTest(@RequestParam String objId){
        List<TreeNode> treeNodeList = deviceDisService.getTreeList(objId);
        // 创建树形结构（数据集合作为参数）
        TreeBuild treeBuild = new TreeBuild(treeNodeList);
        // 原查询结果转换树形结构
        treeNodeList = treeBuild.buildTree();
        // ResultVO：个人封装返回的结果体
        return ResultVO.ok(treeNodeList,"楼层树形结构数据");
    }

    @GetMapping("/coldSite/")
    @ApiOperation(value = "获取设备具体参数")
    public ResultVO coldSite(){
        equipmentBoardService.coldSite();
        return ResultVO.ok("冷站数据");
    }

   @GetMapping("/getArefaction")
   @ApiOperation(value = "除湿除尘概览信息")
   public ResultVO getArefaction(@RequestParam String deviceKey){
       HashMap<String, ArrayList<Dedusting>> result=deviceDisService.getArefaction(deviceKey);
       return ResultVO.ok(result);
   }

}
